import * as actionType from "./actionType";
import { fromJS } from "immutable";
const defaultState = fromJS({
    searchFlag : false,
    inputList:[],
    totlePage: 0,
    currentPage: 1,
    holdFlag : false
})
export default (state = defaultState, action) => {
    switch(action.type) {
        case actionType.SEARCH_FLAG :
            return state.set("searchFlag",!state.get("searchFlag"));
        case actionType.CHANGE_LIST :
            return state.set("inputList",action.inputList).set("totlePage", Math.ceil(action.inputList.size/10));
        case actionType.HOLD_FLAG : 
            return state.set("holdFlag",!state.get("holdFlag"));
        case actionType.CHANGE_PAGE:
            if(state.get("currentPage") === state.get("totlePage")) {
                return state.set("currentPage", 1);
            } else {
                return state.set("currentPage", state.get("currentPage") + 1)
            }
        default :
            return state;
    }
}